﻿using System;

namespace Borg.AttributeAnalyze.Result
{
    public class InvalidDefaultValue : ResultBase
    {
        private readonly ParamDefinition _parameterDefinition;
        private readonly PlugTypeInfo _plug;
        private readonly SlotDefinition _slotDefinition;

        public InvalidDefaultValue(PlugTypeInfo plug, ParamDefinition parameterDefinition)
            : base(plug.Assembly, Component.Plug, ResultType.InvalidDefaultParameter, plug, plug.ExtensionTypeInfo)
        {
            _plug = plug;
            _parameterDefinition = parameterDefinition;
        }

        public InvalidDefaultValue(SlotDefinition slotDefinition, ParamDefinition parameterDefinition)
            : base(slotDefinition.Assembly, Component.SlotDefinition, ResultType.InvalidDefaultParameter, slotDefinition, null)
        {
            _slotDefinition = slotDefinition;
            _parameterDefinition = parameterDefinition;
        }

        public override string ToMsBuildMessageString()
        {
            if (Component == Component.Plug)
                return string.Format(
                    "invalid parameter defaultvalue\n{0}slot name: {1}\n{0}class: {2}\n{0}parameter name:" +
                    " {3}\n{0}parameter type: {4}\n{0}parameter defaultvalue: {5}",
                    new[] { GetWhiteSpace(2), Name, TypeName, _parameterDefinition.Name,
                            _parameterDefinition.Type.Name, _parameterDefinition.DefaultValue });

            if (Component != Component.SlotDefinition)
                throw new NotImplementedException();

            return string.Format(
                "invalid parameter defaultvalue\n{0}slot name: {1}\n{0}interface:" +
                " {2}\n{0}parameter name: {3}\n{0}parameter type: {4}\n{0}parameter defaultvalue: {5}",
                new[] { GetWhiteSpace(2), Name, _slotDefinition.TypeName, _parameterDefinition.Name,
                    _parameterDefinition.Type.Name, _parameterDefinition.DefaultValue });
        }

        public override MessageType MessageType
        {
            get { return MessageType.Error; }
        }
    }
}

